Jerry's Blogs

Monday, October 29, 2007

On Yumify: Places

I woke up this morning and had a pretty clear chain of thought for implementing Places. These are some notes and arguments I came up with.

Issues

  1. Place object is really a reference to a Yelp object returned by Ruby Yelp API
  2. A call needs to be made every time a Place object is created

Peter was absolutely right when he came up with that first statement. It doesn't make sense to use ActiveRecord for an object that will have a single field. It might be convenient because of the methods ActiveRecord provides, but it's kind of cheating... The fix was to simply use a normal object that wraps around a returned Yelp object.

The basic wrapper isn't good enough because it could become stale, and also because a call would need to be made to every Yelp object. Calls would need to be made for the initial query, and there may be repeated calls for each individual result. There would also be calls for each 'favorited' place. The network I/O would kill us.

The solution I came up with is to abstract one more level from the Yelp Ruby API, and create a class called YelpProxy. YelpProxy makes search queries on your behalf, caches the most used results, and returns pre-wrapped Place objects. Here are the pros I came up with this design:

  • A single Yelp::Client can be reused for multiple searches
  • Same benefit of no duplicate data with Yelp.
  • Caching can be implemented by retaining the most frequently fetched. This leads to fewer API calls, and instant access to Place objects.
  • Every fetch can timestamp the Place created. Places can be kept as fresh as needed.
  • All other classes can use Place objects without worrying about constructing it.

There are two places where it made sense to implement these features. The way I have it currently is to have a separate YelpProxy class in the lib/ directory. I like it this way for now because it's easy to understand and edit. The other way is to add caching as an option directly into the Ruby Yelp API. This method might make more sense later and could be helpful to others if we submitted it upstream.

Technical Notes

  • Cache can be a Hash of Place objects with a maximum size. There'd be separate structure (min heap) to keep track of the least used Place.
  • When a request comes into the YelpProxy, check the cache to see if the Place exists. If so, check to see if it's fresh. If so, return that Place, and increment it's 'hotness' in the cache.
  • If any of the above was 'no', then fetch a Yelp object, wrap it in a Place object, and stick it in the cache. Eject the coldest object if the cache is full
  • extra metadata about how many times a Place is fetched. Can be correlated to other factors.

This buys you constant access to the most used Places, and saves a ton of API calls. In fact, since the API is limited to 10,000 calls/day, setting a large size cache would make our site scale much better. For development, a cache size of 50 or so would work.

Labels:

Sunday, October 28, 2007

On Kicking Ass

Here's the daily scoop of what's kicking ass:

  • Andrew and Justin were kicking ass (literally) in the Yongmudo tournament yesterday. The tournament also hosted an exhibitionist team from Korea who kicked a lot of ass. I plan to steal some pics from Wendy Tai later...
  • Lack of sleep is kicking my ass
  • Too much sleep is kicking my ass (I can't win)
  • CS170 problem set, and school in general is kicking my ass
  • Leopard isn't kicking ass per se, more like a wimpy punch at best

Labels:

On OS X Leopard: Miscellaneous

This guy found a great easter egg on Leopard.

My bro found a hilarious 'eulogy' for Mac OS 9 delivered by the Steve

List of what I consider broken:

  • Nighty night widget. Doesn't work at all
  • When switching applications, Spaces will jump to another desktop if the application has a window in another desktop. very very annoying
  • Bitrocket keeps dying
  • PeerGuardian is dead, a lib that it linked to has been removed. See this thread.
  • Front row no longer activated by remote (works now, but didn't earlier. Maybe a sleep issue?
  • Remote no longer controls global sound and play/pause settings (works only within front row
  • Chax = dead. Safari crashed when I tried to write that Chax was dead...

And unrelated, but this article I read on Ars makes me depressed.

Labels: ,

Saturday, October 27, 2007

On OS X Leopard: Terminal

Awesome:
  • Window Settings are in Preferences Menu, rather than hacked on
  • Window groupings remove the need for my AppleScript hack to save a workspace of terminals
  • Colorful profiles of terminal settings. Cute, but useless

Labels: ,

On OS X Leopard: First Contact

There have been screenshots and reviews galore all over the net. After the suspenseful buildup, a Leopard beanie baby, and a belly full of complimentary pizza from The Scholar's Workstation, I feel I've calmed to a state where I can pass quick judgement on Apple's latest and greatest.

What works right away in Apple's favor is the pure hype generated by the news, and by rabid mac fanboys. The sound of "Leopard Launch Party" made me cringe inside; Who's ever heard of a launch party for an OS before?

The cringing quickly stopped when I learned about the free pizza and cheesy beard at TSW. I've got a soft spot for cheesy beard...

What continued to work after the unchecked gorging of carbohydrates was the Leopard installer. I've gone through more Windows installations in my life than your average computer user, so the raw blue screen and cryptic messages don't phase me the slightest. In contrast, Leopard's installer manages to do the entire installation in circa 3 mouse clicks: Install, Agree, Continue. I chose the upgrade method for both my iBook and iMac, and neither had conflicts or complaints. It approaches the CBM-ness of 'apt', but hits the wallet a wee bit more.

After all the initial loading and indexing, a rigorously detailed BS performance benchmark was run on both Macs in question. The iBook came in at a whopping 63.5% slower than the Tiger version. What's even more painful is the noticeable hiccup whenever any form of eye candy is executed. It's borderline enough to render some features like Quick Look and Cover Flow useless. Wendy Tai is wise for not installing it on her iBook. The iMac is a completely different story. Using the same benchmark for the iBook, I'd say that Leopard has a gut feeling performance gain of 0% on my iMac. Fortunately, this discouraging figure is compensated by working features like Spaces (it recognized my dual monitor setup), and Quick Look. I can already see Quick Look adding 1 maybe even 2% to my productivity.

more later... (Time Machine. zomg)

Labels: ,

Monday, October 22, 2007

On Audi R8 Top Gear Review

This show is freaking hilarious and awesome at the same time. The 10th season started not too long ago, and I'm glad that it's kept the same Top Gear flavor. I am a little disappointed with them reusing the amphibious cars challenge in the 2nd episode.
This like rubbing honey on Keira Knightley's body. -Jeremy Clarkson on Audi R8

Labels:

Wednesday, October 17, 2007

On Web 2.0: The Machine is Us/ing Us

I saw this fantastic video explanation of Web 2.0 in art class today. This videos are by Michael Wesch. Another video about slacker students, myself included.

Labels:

Tuesday, October 16, 2007

On Learning Cocoa and OS X Development

It's an exciting time to learn to develop on the OS X platform. Apple's doing great as a company with lots of fresh new products, more people are switching to Macs, and OSX 10.5 Leopard will be coming out anyday now... (knock on wood). I've been meaning to the development environment on the Mac for a while now, but have put it off because of laziness and getting p0wn3d in various classes. Thankfully, this semester has been super chill so far (double knock on wood), leaving me with enough time to sleep lots, and learn Cocoa.

Cocoa is a programming framework that consists of 3 often used frameworks: ApplicationKit (a.k.a AppKit), Foundation, and CoreData. AppKit gives you all the GUI controls, and Foundation gives you all the basic data structures and tools. I haven't gotten to CoreData yet. It's about 5 weeks into the semester, and I'm about a third of the way through Cocoa(R) Programming for Mac(R) OS X. I've just been going chapter by chapter and doing all the examples. The books is great because it's split into very short lessons that are conversational. It's easy to just do a chapter or a few sections within a chapter every other day.

There are just somethings I'm really having a good time with while I'm learning this.

  • Objective-C was a breeze to pick up since it's just C with some syntactic sugar
  • Memory management is fun! ... in a sadistic way. I squashed my first memory bug today where I was trying to send a message to an object that was already deallocated.
  • I really like the prevalent use of the delegate pattern in the frameworks and how well integrated it is with the UI controls
  • Interface Builder rocks my socks off. I like how UI controls are actually instantiated, and serialized to a nib file rather than instantiated and generated at runtime. This way, when an app starts up, it can just auto un-serialize the appropriate nibs. I also really dig how IB will draw guidelines in your GUI layout to suggest how you can conform to Apple's Human Interface Guidelines
  • I like how there's static typing and dynamic typing, and I REALLY like the dynamic behavior you can get with messaging tricks at runtime. Think selectors, forwardInvocation, and nil responding to all messages.

Wednesday, October 10, 2007

On Relaxing Before I Bleed to Death

I think I've always obsessed about money. I've already told this to Wendy and other people many times, but no one seems to _get_ it. Maybe I don't really understand it myself. Anyways, part of what bothers me is how other people look down on this obsession. People's reactions range hesitant and pitying all the way to outraged and disgusted. Had I been born with an obsession to save baby seals, I'm sure the reactions would change drastically.

I think of it more as a practical hobby. When I'm bored, one of the things I like to do is to make money. It's a game. It's rewarding. And at the end of the day, the money comes out as a bonus. I'm not exploiting people, and no baby seals are dying as a result. So why is my hobby such a bad thing?

On Sh!+#y S1t3s (Shitty Sites)

I'm constantly amazed by the level of incompetence I run across for sites I expect to do better.

  • TMobile - Damn you and your non-functional browser dependent javascript submissions. I tried and failed to change myFaves using Safari. I thought the whole point of Faves was to cater to young people? I would imagine there'd be at least say, oh a few young folks, who use Macs. But then again, you probably gave Catherine Zeta Jones all you money, so you couldn't pay the extra 10 g's to make a freaking site that works. Update: There is one nice feature where they use a clever width and fill css trick to display the number of minutes used. Unfortunately, this is cancelled out by the fact that returning to the main page after login forces you to re-login again.
  • I-131 Electronic Form - This was a pleasant surprise followed by a laughably funny form wizard. The I-131 is a government form for applying for a reentry permit. First of all, finding this wizard was non-trivial, and I only came across it by luck. When I started it, it would take you through a series of screens of questions. My favorite part was how it would give a deathly scary big bold red warning when you failed to enter your middle initial. When did middle initials become required?
  • Golds Gym - This little gem is subtle yet deadly (to my wallet). I signed up for a summer package while I was in Austin. Halfway through, I asked how to cancel and was given a single option: fill in a form, mail it in, wait 30 days and pray. Well, I must've forgotten to pray because 30 days later I get an automatic charge on my credit card. What's worse is that when I look on the site or call in, there's no web system to cancel membership! You have to once again: snail mail, or fax, or email. The email doesn't sound so bad until you realize it isn't an automated system, but rather you email a team of underpaid workers actually reading your request and 'reviewing your case'. It doesn't matter how sweet your customer support phone person sounds. Golds Gym, you take the cake for shittiest customer care.

Labels:

Friday, October 5, 2007

On CSS Menu Hacks

I've always wanted to emulate Apple's navigation bar. I've seen other similar navigation's that changed the background image on mouse hover. But this navigation bar went one further and has another special state for on mouse click that draws an outline on the button. So I whipped out my Firebug and dug into how this sucka worked.

It turns out to not be tedious and slow javascript operation, but a rather clever CSS hack. Instead of messing with the DOM whenever there's a mouse event, the clever solution is to selectively shift the background image around until the correct 'image state' is in view. In the image above, when a mouse hovers over a button, we shift the image up a row. To prevent all the buttons from being in a hover state, just have each button keeps a reference to it's own shifted background image. For a good clean tutorial, check out ghettocooler.

Labels: , ,

On OLPC

I haven't been following the OLPC project very closely, but I ran across a NY Times article on it today. This shows a few things. For starters, I still hate David Pogue because he dumbs down technology too much for my tastes. Fortunately, the fact that it's him writing on a paper whose tagline is "All the news that's fit to print" means that the project is both alive and receiving a new fresh jolt of interest.

I'm a huge fan of the machine and it's guiding design principles. It's engineering and open source at it's best. The laptop needs to have a long lasting battery, be built of cheap components, survive the harsh environments of underdeveloped countries and the grubby fingers of children. And as if each of these alone weren't lofty enough goals, the device has to be FUN enough to use. It's freaking amazing this can be done.

Not only is it an amazing feat of hardware, but they've also made sure the software doesn't waste it. The interface is thought up from the ground up, and focused for it's audience. The software is open and allows children to poke around in the source. That means that future developments are also open!

Labels: , ,

Wednesday, October 3, 2007

On Captcha's, and Analytics.

Captcha's are a sort of reverse Turing test. Instead of humans trying to call out computers, computers are trying to call out computers. The idea's easy enough. To prevent the endless torrents of spam from form submissions, you could make a simple human test to make sure the submissions are from people rather than bots.

Here are some different implementations. I'll update this list if I find any other clever solutions.

  • Official Captcha - CMU was first to write a paper about it. They also have this great project called reCaptcha that uses bad OCR images of books being digitized. This can help with efforts to digitize crumbling literature! On top of that, they provide an accessible captcha for the visually impaired by reading out the word.
  • Logic Captcha - Instead of using an image, generate some trivial arithmetic problems, or simple trivia problems for the user to solve
  • Honeypot Captcha - I'm a fan of this one too because of it's clever use of CSS. On top of being accessible, it's completely idiot proof because the user passes if he doesn't do anything! The way it works is to have an extra form input field that's hidden by CSS. A mere mortal would simply skip this field and leave it blank, but a malicious bot would fill it in anyways. Simply discard all POSTs where this field is filled.

Mint looks like a very promising, and very cheap solution to do site analytics. Google also provides a free analytics tool that pairs up well with their Adwords program.

Labels: ,

Monday, October 1, 2007

On Safari 3 Goodness

I came across the public beta for Safari that will be included in OS X's next upcoming release, 10.5 Leopard. I figured that the public beta had to be pretty stable at this point and decided to give it a whirl. Click the image to see an animated gif of the features.

The tab rearrange thing I've taken for granted in Firefox is available. Not a bad feature, but kind of on the boring side.

What dazzled me was Apple's remix of 'Find as you type'. Just this feature alone makes the new Safari worthwhile. If they changed nothing else, I would still be happy. The screenshot doesn't do this feature justice. As you start typing in the find box, each matched orange box makes a popping animation for each matched character. It's very cartoonish and directs your attention to the next available match.

All my annoyances are still alive and pesky as ever. To get the screenshot up, I had to use Firefox because the dialog to upload image would either be blank, or fail to upload. Also, my resumes page is as hideous as ever because Safari doesn't like microformats.

Labels: